package itsm.isperp.report.paser;

import itsm.isperp.framework.utils.DateUtils;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 
 * 
 * 
 * @author lizx
 * @date 2015-9-6
 * @since 1.0
 * 
 */
public class QueryLineByMonthPaser {

	public static QueryLineLegend paser(Date startDate, Date endDate,
			boolean line) {
		QueryLineLegend m = new QueryLineLegend();
		Calendar scal = Calendar.getInstance();
		scal.setTime(endDate);
		String ed = DateUtils.formatDate(endDate);

		List<String> ds = new ArrayList<>();

		//scal.set(Calendar.MONTH, scal.get(Calendar.MONTH) - 3);
		scal.add(Calendar.MONTH, -3);
		ds.add(DateUtils.formatYearMonth(scal.getTime()));

		scal.setTime(endDate);
		scal.add(Calendar.MONTH, -2);
		ds.add(DateUtils.formatYearMonth(scal.getTime()));

		scal.setTime(endDate);
		scal.add(Calendar.MONTH, -1);
		ds.add(DateUtils.formatYearMonth(scal.getTime()));

		ds.add(DateUtils.formatYearMonth(endDate));

		if (line) {
			m.setStart(ds.get(0) + "-01");
		} else {
			scal.setTime(startDate);
			m.setStart(DateUtils.formatDate(scal.getTime()));
		}

		m.setEnd(ed);
		m.setValues(ds);

		m.setDateFormat("yyyy-mm");
		return m;
	}
}
